(function () {
  'use strict';

  angular
    .module('client')
    .factory('utilService', utilService);

  utilService.$inject = [];
  function utilService() {
    var services = {
      timeConvertToServer: timeConvertToServer,
      timeConvertToWeb: timeConvertToWeb,
      formatNumber: formatNumber,

    };
    return services;

    function timeConvertToServer(localTime) {  //convert local time into server's time format
      return localTime.toISOString();
    }

    function timeConvertToWeb(serverTime) {     //convert server's time into local's time format
      var t = new Date(serverTime);
      return Date.parse(t);
    }

    function formatNumber(num, n) {
      var tbl = [];
      return function(num, n) {
        var len = n-num.toString().length;
        if (len <= 0) return num;
        if (!tbl[len]) tbl[len] = (new Array(len+1)).join('0');
        return tbl[len] + num;
      }(num, n)
    }

  }
})();
